package com.zhanghe.study.design_pattern.memento_pattern;

/**
 * 原发器
 * @author zh
 * @date 2022/10/18 11:51
 */
public class Origintor {
    private String state;

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public Memento createMemento(){
        return new MementoImpl(state);
    }

    // 重置原发器状态，回到备忘录中的状态
    public void setMemento(Memento memento){
        MementoImpl memento1 = (MementoImpl) memento;
        this.state = memento1.getState();
    }

    // 备忘录实现，私有内部类，不能被外部访问
    private static class MementoImpl implements Memento{

        private String state;

        public MementoImpl(String state){
            this.state = state;
        }

        public String getState() {
            return state;
        }
    }
}
